package com.chinawayltd.ews.sample.util;

import com.alibaba.fastjson.JSONObject;
import com.chinawayltd.ews.sample.util.grid.Page;

/**
 * Created by yuanqiang on 2018/4/10.
 */
public class ResultModel {
    public static final int SUB_CODE_SYSTEM_ERROR = 99;
    public static final int CODE_TOKEN_INVALID = 100000;

    private int code = 0;//0：为true，1：false
    private int sub_code = 0;
    private JSONObject data;

    public ResultModel() {
		super();
	}

	public ResultModel(int code, int sub_code, JSONObject data) {
		super();
		this.code = code;
		this.sub_code = sub_code;
		this.data = data;
	}

	public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getSub_code() {
        return sub_code;
    }

    public void setSub_code(int sub_code) {
        this.sub_code = sub_code;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public void setSub_msg(String msg){
        if(data == null){
            data = new JSONObject();
        }
        data.put("sub_msg", msg);
    }

    public void setMsg(String msg){
        if(data == null){
            data = new JSONObject();
        }
        data.put("msg", msg);
    }

    public void setPage(Page page){
        if(page != null){
            if(data == null){
                data = new JSONObject();
            }
            data.fluentPut("totalCount", page.getCount())
                    .fluentPut("pageSize", page.getPageSize())
                    .fluentPut("pageNo", page.getPageNo());
        }
    }
}
